package com.example.lib_base.net

import com.blankj.utilcode.util.SPUtils
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

object RetrofitUtils {

    fun getOKHttpClient():OkHttpClient{
        return OkHttpClient.Builder()
            .connectTimeout(30,TimeUnit.SECONDS)
            .writeTimeout(30,TimeUnit.SECONDS)
            .readTimeout(30,TimeUnit.SECONDS)
            .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .addInterceptor {
                val build = it.request().newBuilder()
                    .addHeader("token","sss")
                    .addHeader("accessId","75f5ead309c147a189efe32f503b5411").build()
                return@addInterceptor it.proceed(build)
            }
            .build()
    }

    fun getRetrofit():Retrofit{
        return Retrofit.Builder()
            .baseUrl(Const.BASE_URL)
            .client(getOKHttpClient())
            .addConverterFactory(GsonConverterFactory.create())
            .build()
    }
}